var express = require('express');
var mysql = require('mysql');

let query = function (key){
     return "select sellerID from `seller` where name like '%"+key+"%' union select sellerID from" +
        " `menu` where menu like '%"
        +key+"%'"
}
var search = function (key, callback){
    //建立连接
    var connection = mysql.createConnection({
        host     : '148.70.88.72',
        user     : 'test',
        password : '5280d5e6515378d4',
        database : 'test'
    })
    //启动连接
    connection.connect(function (err){
        if(err)
            console.log(err);
    });
    connection.query(query(key), function (err, result) {
        if (err) throw err;
        //打印查询结果
        var arr1 = [];
        for(let i in result){
            arr1.push(result[i].sellerID);
        }
        callback(arr1);
        connection.end();
    })
}
exports.search = search;
